<?php


/**
 * Page class.
**/
class Page extends MrMongoDocument {
	
	public $uid; 
	public $pid;
	public $pageno;
	public $createdate;
	public $updatedate;
	public $widgets;

	/**
	* This method have to be defined in every Model
	* @return string MongoDB collection name, witch will be used to store documents of this model
	*/
	public function getCollectionName() {
		return 'pages';
	}	
	
	
    /**
     * This method should return simple array that will define field names for embedded
     * documents, and class to use for them
     */ 
    public function behaviors()
    {

		return array(
            'embeddedArrays' => array(
                'class'=>'ext.YiiMongoDbSuite.extra.EEmbeddedArraysBehavior',
                'arrayPropertyName'=>'widgets',       // name of property, that will be used as an array
                'arrayDocClassName'=>'Widget'    // class name of embedded documents in array
            ),
        );
    }

	/**
	 * This method have to be defined in every model, like with normal CActiveRecord
	 */
	public static function model($className = __CLASS__) {
		return parent :: model($className);
	}

	public static function findByUid($uid) {
		return $pages = self :: model()->findByAttributes(array ('uid' => $uid));
	}
	
	public static function findByPid($pid) {
		return $page = self :: model()->findByAttributes(array ('pid' => $pid));
	}

	public static function findByUidNo($uid,$pageNo) {
	    return $page = self :: model()->findByAttributes(array ('uid' => $uid,'pageno'=>$pageNo));
	}
	public static function findFirstPageByUid($uid){
		//echo $uid;
		 return $page = self :: model()->findByUidNo($uid,"1");
	}
}